'use strict';

const Controller = require('../base');

class Finance extends Controller {
  /*
    #增
    */

  async addIncome() {
    const { ctx } = this;
    try {
      const income = await ctx.service.finance.finance.addIncome(
        ctx.request.body
      );
      this.success({ income });
    } catch (error) {
      this.error(error);
    }
  }

  async addExpense() {
    const { ctx } = this;
    try {
      const expense = await ctx.service.finance.finance.addExpense(
        ctx.request.body
      );
      this.success({ expense });
    } catch (error) {
      this.error(error);
    }
  }
  /*
    #删
    */
  /* 改
   */
  // 收入审核
  async examineIncome() {
    const { ctx } = this;
    try {
      const res = await ctx.service.finance.finance.examineIncome(
        ctx.request.body
      );
      this.success(res);
    } catch (error) {
      this.error(error);
    }
  }
  // 支出审核
  async examineExpense() {
    const { ctx } = this;
    try {
      const res = await ctx.service.finance.finance.examineExpense(
        ctx.request.body
      );
      this.success(res);
    } catch (error) {
      this.error(error);
    }
  }
  /*
     查
   */
  // 待审核收入列表
  async findNewIncomeList() {
    const { ctx } = this;
    const list = await ctx.service.finance.finance.findNewIncomeList();
    this.success(list);
  }
  // 根据状态查询列表
  async findIncomeListByState() {
    const { ctx } = this;
    ctx.validate({
      state: {
        required: true,
      },
    });
    const list = await ctx.service.finance.finance.findIncomeListByState(
      ctx.request.body
    );
    this.success(list);
  }
  // 完成审核收入列表
  async FindExaminedIncomeList() {
    const { ctx } = this;
    const list = await ctx.service.finance.finance.FindExaminedIncomeList();
    this.success(list);
  }
  // 待审核支出列表
  async findNewExpenseList() {
    const { ctx } = this;
    const list = await ctx.service.finance.finance.findNewExpenseList();
    this.success(list);
  }
  // 完成审核支出列表
  async findExamineExpenseList() {
    const { ctx } = this;
    const list = await ctx.service.finance.finance.findExamineExpenseList();
    this.success(list);
  }
}
module.exports = Finance;
